package com.lyc.service.impl;

import com.lyc.dao.UserDao;
import com.lyc.service.LoginService;
import com.lyc.util.JwtUtil;
import com.lyc.vo.LoginVo;
import com.lyc.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/23 23:16
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private UserDao userDao;
    @Override
    public Result login(LoginVo loginVo) {
        String password = userDao.selectByPassword(loginVo);
        if (password.equals(password)){
            Map<String, Object> map = new HashMap<>();
            map.put("username",loginVo.getUsername());
            String token = JwtUtil.createToken(map);
            System.out.println(token);
            return new Result(2000,"登录成功",token);
        }else {
            return new Result(5000,"密码错误");
        }
    }
}